package com.ruoyi.system.controller;

import cn.xiaosiyuan.util.genId.PKGenerator;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TbCarAnnualInspectionInspection;
import com.ruoyi.system.service.ITbCarAnnualInspectionInspectionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 年检记录Controller
 * 
 * @author xiaosiyuan
 * @date 2021-11-12
 */
@RestController
@RequestMapping("/system/annualInspection")
public class TbCarAnnualInspectionInspectionController extends BaseController
{
    @Autowired
    private ITbCarAnnualInspectionInspectionService tbCarAnnualInspectionInspectionService;

    /**
     * 查询年检记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:annualInspection:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbCarAnnualInspectionInspection tbCarAnnualInspectionInspection)
    {
        startPage();
        List<TbCarAnnualInspectionInspection> list = tbCarAnnualInspectionInspectionService.selectTbCarAnnualInspectionInspectionList(tbCarAnnualInspectionInspection);
        return getDataTable(list);
    }

    /**
     * 导出年检记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:annualInspection:export')")
    @Log(title = "年检记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TbCarAnnualInspectionInspection tbCarAnnualInspectionInspection)
    {
        List<TbCarAnnualInspectionInspection> list = tbCarAnnualInspectionInspectionService.selectTbCarAnnualInspectionInspectionList(tbCarAnnualInspectionInspection);
        ExcelUtil<TbCarAnnualInspectionInspection> util = new ExcelUtil<TbCarAnnualInspectionInspection>(TbCarAnnualInspectionInspection.class);
        return util.exportExcel(list, "年检记录数据");
    }

    /**
     * 获取年检记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:annualInspection:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(tbCarAnnualInspectionInspectionService.selectTbCarAnnualInspectionInspectionById(id));
    }

    /**
     * 新增年检记录
     */
    @PreAuthorize("@ss.hasPermi('system:annualInspection:add')")
    @Log(title = "年检记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbCarAnnualInspectionInspection tbCarAnnualInspectionInspection)
    {
        tbCarAnnualInspectionInspection.setId(PKGenerator.newId());
        return toAjax(tbCarAnnualInspectionInspectionService.insertTbCarAnnualInspectionInspection(tbCarAnnualInspectionInspection));
    }

    /**
     * 修改年检记录
     */
    @PreAuthorize("@ss.hasPermi('system:annualInspection:edit')")
    @Log(title = "年检记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbCarAnnualInspectionInspection tbCarAnnualInspectionInspection)
    {
        return toAjax(tbCarAnnualInspectionInspectionService.updateTbCarAnnualInspectionInspection(tbCarAnnualInspectionInspection));
    }

    /**
     * 删除年检记录
     */
    @PreAuthorize("@ss.hasPermi('system:annualInspection:remove')")
    @Log(title = "年检记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tbCarAnnualInspectionInspectionService.deleteTbCarAnnualInspectionInspectionByIds(ids));
    }
}
